import {
    select_resourceAddObj,
    add_resourceAddObj,
    delete_resourceAddObj,
    update_resourceAddObj
  } from "@/api/resource_page.js";
  // 机构管理
  const state = {
    resourceSeclect: {},
    resourceListItem: {}
  };
  
  const mutations = {
    //resourceListItem
    SET_RESOURCELISTITEM(state, val) {
      state.resourceListItem = val;
    },
    // resourceSeclect
    SET_RESOURCESELECT(state, val) {
      state.resourceSeclect = val;
    },
  };
  
  const actions = {
//     // 添加
    add_resourceAddObj({ commit }, val) {
      commit("SET_RESOURCELISTITEM", val);
      return new Promise((resolve, reject) => {
        add_resourceAddObj(val)
          .then(res => {
            if (res && res.data && res.data.code === "000000") {
              resolve(true);
            } else {
              resolve(false);
            }
          })
          .catch(err => {
            reject(false);
          });
      });
    },
    // 修改
    update_resourceAddObj({ commit }, val) {
      commit("SET_RESOURCELISTITEM", val);
      return new Promise((resolve, reject) => {
        update_resourceAddObj(val)
          .then(res => {
            if (res && res.data && res.data.code === "000000") {
              resolve(true);
            } else {
              resolve(false);
            }
          })
          .catch(err => {
            reject();
          });
      });
    },
//     // 修改显示
//     updateshow_commonAddObj({ commit }, val) {
//       commit("SET_COMMONLISTITEM", val);
//       return new Promise((resolve, reject) => {
//         updateshow_commonAddObj(val)
//           .then(res => {
//             resolve();
//           })
//           .catch(err => {
//             reject();
//           });
//       });
//     },
    // 删除
    delete_resourceAddObj({ commit }, val) {
      return new Promise((resolve, reject) => {
        delete_resourceAddObj(val)
          .then(res => {
            if (res && res.data && res.data.code === "000000") {
              resolve(true);
            } else {
              resolve(false);
            }
          })
          .catch(err => {
            reject();
          });
      });
    },
    // 点击编辑存放的数据
    list_resourceListItem({ commit }, val) {
      commit("SET_RESOURCELISTITEM", val);
    },
    // 点击查询
    select_resource({ commit }, val) {
      // 存放查询数据
      commit("SET_RESOURCESELECT", val);
      // 发送请求
      return new Promise((resolve, reject) => {
        select_resourceAddObj(val)
          .then(res => {
            // 数据列表里面添加数据
            const { data } = res.data;
            resolve(data);
          })
          .catch(err => {
            reject();
          });
      });
    }
  };
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  };
  